<?php
define("EW_PAGE_ID", "search", TRUE); // Page ID
define("EW_TABLE_NAME", 'HoaDonPhim', TRUE);
?>
<?php 
session_start(); // Initialize session data
ob_start(); // Turn on output buffering
?>
<?php include "ewcfg50.php" ?>
<?php include "ewmysql50.php" ?>
<?php include "phpfn50.php" ?>
<?php include "HoaDonPhiminfo.php" ?>
<?php include "userfn50.php" ?>
<?php include "usersinfo.php" ?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php

// Open connection to the database
$conn = ew_Connect();
?>
<?php
$Security = new cAdvancedSecurity();
?>
<?php
if (!$Security->IsLoggedIn()) $Security->AutoLogin();
$Security->LoadCurrentUserLevel('HoaDonPhim');
if (!$Security->IsLoggedIn()) {
	$Security->SaveLastUrl();
	Page_Terminate("login.php");
}
if (!$Security->CanSearch()) {
	$Security->SaveLastUrl();
	Page_Terminate("HoaDonPhimlist.php");
}
?>
<?php

// Common page loading event (in userfn*.php)
Page_Loading();
?>
<?php

// Page load event, used in current page
Page_Load();
?>
<?php
$HoaDonPhim->Export = @$_GET["export"]; // Get export parameter
$sExport = $HoaDonPhim->Export; // Get export parameter, used in header
$sExportFile = $HoaDonPhim->TableVar; // Get export file, used in header
?>
<?php

// Get action
$HoaDonPhim->CurrentAction = @$_POST["a_search"];
switch ($HoaDonPhim->CurrentAction) {
	case "S": // Get Search Criteria

		// Build search string for advanced search, remove blank field
		$sSrchStr = BuildAdvancedSearch();
		if ($sSrchStr <> "") {
			Page_Terminate("HoaDonPhimlist.php?" . $sSrchStr); // Go to list page
		}
		break;
	default: // Restore search settings
		LoadAdvancedSearch();
}

// Render row for search
$HoaDonPhim->RowType = EW_ROWTYPE_SEARCH;
RenderRow();
?>
<?php include "header.php" ?>
<script type="text/javascript">
<!--
var EW_PAGE_ID = "search"; // Page id
var EW_SHOW_HIGHLIGHT = "Show highlight"; 
var EW_HIDE_HIGHLIGHT = "Hide highlight";

//-->
</script>
<script type="text/javascript">
<!--

function ew_ValidateForm(fobj) {
	if (fobj.a_confirm && fobj.a_confirm.value == "F")
		return true;
	var i, elm, aelm, infix;
	var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
	for (i=0; i<rowcnt; i++) {
		infix = (fobj.key_count) ? String(i+1) : "";
		elm = fobj.elements["x" + infix + "_dateadd"];
		if (elm && !ew_CheckEuroDate(elm.value)) {
			if (!ew_OnError(elm, "Incorrect date, format = dd/mm/yyyy - dateadd"))
				return false; 
		}
		elm = fobj.elements["x" + infix + "_quantity"];
		if (elm && !ew_CheckNumber(elm.value)) {
			if (!ew_OnError(elm, "Incorrect floating point number - quantity"))
				return false; 
		}
	}
	return true;
}

//-->
</script>
<script type="text/javascript">
<!--
var ew_DHTMLEditors = [];

//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your client script here, no need to add script tags.
// To include another .js script, use:
// ew_ClientScriptInclude("my_javascript.js"); 
//-->

</script>
<p><span class="phpmaker">Search CUSTOM VIEW: Hoa Don Phim<br><br><a href="HoaDonPhimlist.php">Back to List</a></span></p>
<form name="fHoaDonPhimsearch" id="fHoaDonPhimsearch" action="HoaDonPhimsrch.php" method="post" onSubmit="return ew_ValidateForm(this);">
<p>
<input type="hidden" name="a_search" id="a_search" value="S">
<table class="ewTable">
	<tr class="ewTableRow">
		<td class="ewTableHeader">bill</td>
		<td<?php echo $HoaDonPhim->bill->CellAttributes() ?>><span class="ewSearchOpr">contains<input type="hidden" name="z_bill" id="z_bill" value="LIKE"></span></td>
		<td<?php echo $HoaDonPhim->bill->CellAttributes() ?>><span class="phpmaker">
<select id="x_bill" name="x_bill"<?php echo $HoaDonPhim->bill->EditAttributes() ?>>
<!--option value="">Please Select</option-->
<?php
if (is_array($HoaDonPhim->bill->EditValue)) {
	$arwrk = $HoaDonPhim->bill->EditValue;
	$rowswrk = count($arwrk);
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($HoaDonPhim->bill->AdvancedSearch->SearchValue) == strval($arwrk[$rowcntwrk][0])) ? " selected" : "";	
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
			}
}
?>
</select>
</span></td>
	</tr>
	<tr class="ewTableAltRow">
		<td class="ewTableHeader">fullname</td>
		<td<?php echo $HoaDonPhim->fullname->CellAttributes() ?>><span class="ewSearchOpr">contains<input type="hidden" name="z_fullname" id="z_fullname" value="LIKE"></span></td>
		<td<?php echo $HoaDonPhim->fullname->CellAttributes() ?>><span class="phpmaker">
<input type="text" name="x_fullname" id="x_fullname"  size="30" maxlength="250" value="<?php echo $HoaDonPhim->fullname->EditValue ?>"<?php echo $HoaDonPhim->fullname->EditAttributes() ?>>
</span></td>
	</tr>
	<tr class="ewTableRow">
		<td class="ewTableHeader">email</td>
		<td<?php echo $HoaDonPhim->email->CellAttributes() ?>><span class="ewSearchOpr">contains<input type="hidden" name="z_email" id="z_email" value="LIKE"></span></td>
		<td<?php echo $HoaDonPhim->email->CellAttributes() ?>><span class="phpmaker">
<input type="text" name="x_email" id="x_email"  size="30" maxlength="250" value="<?php echo $HoaDonPhim->email->EditValue ?>"<?php echo $HoaDonPhim->email->EditAttributes() ?>>
</span></td>
	</tr>
	<tr class="ewTableAltRow">
		<td class="ewTableHeader">address</td>
		<td<?php echo $HoaDonPhim->address->CellAttributes() ?>><span class="ewSearchOpr">contains<input type="hidden" name="z_address" id="z_address" value="LIKE"></span></td>
		<td<?php echo $HoaDonPhim->address->CellAttributes() ?>><span class="phpmaker">
<input type="text" name="x_address" id="x_address"  size="30" maxlength="250" value="<?php echo $HoaDonPhim->address->EditValue ?>"<?php echo $HoaDonPhim->address->EditAttributes() ?>>
</span></td>
	</tr>
	<tr class="ewTableRow">
		<td class="ewTableHeader">tel</td>
		<td<?php echo $HoaDonPhim->tel->CellAttributes() ?>><span class="ewSearchOpr">contains<input type="hidden" name="z_tel" id="z_tel" value="LIKE"></span></td>
		<td<?php echo $HoaDonPhim->tel->CellAttributes() ?>><span class="phpmaker">
<input type="text" name="x_tel" id="x_tel"  size="30" maxlength="15" value="<?php echo $HoaDonPhim->tel->EditValue ?>"<?php echo $HoaDonPhim->tel->EditAttributes() ?>>
</span></td>
	</tr>
	<tr class="ewTableAltRow">
		<td class="ewTableHeader">note</td>
		<td<?php echo $HoaDonPhim->note->CellAttributes() ?>><span class="ewSearchOpr">contains<input type="hidden" name="z_note" id="z_note" value="LIKE"></span></td>
		<td<?php echo $HoaDonPhim->note->CellAttributes() ?>><span class="phpmaker">
<textarea name="x_note" id="x_note" cols="35" rows="4"<?php echo $HoaDonPhim->note->EditAttributes() ?>><?php echo $HoaDonPhim->note->EditValue ?></textarea>
</span></td>
	</tr>
	<tr class="ewTableRow">
		<td class="ewTableHeader">dateadd</td>
		<td<?php echo $HoaDonPhim->dateadd->CellAttributes() ?>><span class="ewSearchOpr">=<input type="hidden" name="z_dateadd" id="z_dateadd" value="="></span></td>
		<td<?php echo $HoaDonPhim->dateadd->CellAttributes() ?>><span class="phpmaker">
<input type="text" name="x_dateadd" id="x_dateadd"  value="<?php echo $HoaDonPhim->dateadd->EditValue ?>"<?php echo $HoaDonPhim->dateadd->EditAttributes() ?>>
</span></td>
	</tr>
	<tr class="ewTableAltRow">
		<td class="ewTableHeader">quantity</td>
		<td<?php echo $HoaDonPhim->quantity->CellAttributes() ?>><span class="ewSearchOpr">=<input type="hidden" name="z_quantity" id="z_quantity" value="="></span></td>
		<td<?php echo $HoaDonPhim->quantity->CellAttributes() ?>><span class="phpmaker">
<input type="text" name="x_quantity" id="x_quantity"  size="30" value="<?php echo $HoaDonPhim->quantity->EditValue ?>"<?php echo $HoaDonPhim->quantity->EditAttributes() ?>>
</span></td>
	</tr>
</table>
<p>
<input type="submit" name="Action" id="Action" value="  Search  ">
<input type="button" name="Reset" id="Reset" value="   Reset   " onclick="ew_ClearForm(this.form);">
</form>
<script language="JavaScript" type="text/javascript">
<!--

// Write your table-specific startup script here
// document.write("page loaded");
//-->

</script>
<?php include "footer.php" ?>
<?php

// If control is passed here, simply terminate the page without redirect
Page_Terminate();

// -----------------------------------------------------------------
//  Subroutine Page_Terminate
//  - called when exit page
//  - clean up connection and objects
//  - if url specified, redirect to url, otherwise end response
function Page_Terminate($url = "") {
	global $conn;

	// Page unload event, used in current page
	Page_Unload();

	// Global page unloaded event (in userfn*.php)
	Page_Unloaded();

	 // Close Connection
	$conn->Close();

	// Go to url if specified
	if ($url <> "") {
		ob_end_clean();
		header("Location: $url");
	}
	exit();
}
?>
<?php

// Build advanced search
function BuildAdvancedSearch() {
	global $HoaDonPhim;
	$sSrchUrl = "";

	// Field bill
	BuildSearchUrl($sSrchUrl, $HoaDonPhim->bill, @$_POST["x_bill"], @$_POST["z_bill"], @$_POST["v_bill"], @$_POST["y_bill"], @$_POST["w_bill"]);

	// Field fullname
	BuildSearchUrl($sSrchUrl, $HoaDonPhim->fullname, @$_POST["x_fullname"], @$_POST["z_fullname"], @$_POST["v_fullname"], @$_POST["y_fullname"], @$_POST["w_fullname"]);

	// Field email
	BuildSearchUrl($sSrchUrl, $HoaDonPhim->email, @$_POST["x_email"], @$_POST["z_email"], @$_POST["v_email"], @$_POST["y_email"], @$_POST["w_email"]);

	// Field address
	BuildSearchUrl($sSrchUrl, $HoaDonPhim->address, @$_POST["x_address"], @$_POST["z_address"], @$_POST["v_address"], @$_POST["y_address"], @$_POST["w_address"]);

	// Field tel
	BuildSearchUrl($sSrchUrl, $HoaDonPhim->tel, @$_POST["x_tel"], @$_POST["z_tel"], @$_POST["v_tel"], @$_POST["y_tel"], @$_POST["w_tel"]);

	// Field note
	BuildSearchUrl($sSrchUrl, $HoaDonPhim->note, @$_POST["x_note"], @$_POST["z_note"], @$_POST["v_note"], @$_POST["y_note"], @$_POST["w_note"]);

	// Field dateadd
	BuildSearchUrl($sSrchUrl, $HoaDonPhim->dateadd, ew_UnFormatDateTime(@$_POST["x_dateadd"],7), @$_POST["z_dateadd"], @$_POST["v_dateadd"], ew_UnFormatDateTime(@$_POST["y_dateadd"],7), @$_POST["w_dateadd"]);

	// Field quantity
	BuildSearchUrl($sSrchUrl, $HoaDonPhim->quantity, @$_POST["x_quantity"], @$_POST["z_quantity"], @$_POST["v_quantity"], @$_POST["y_quantity"], @$_POST["w_quantity"]);
	return $sSrchUrl;
}

// Function to build search URL
function BuildSearchUrl(&$Url, &$Fld, $FldVal, $FldOpr, $FldCond, $FldVal2, $FldOpr2) {
	$sWrk = "";
	$FldParm = substr($Fld->FldVar, 2);
	$FldVal = ew_StripSlashes($FldVal);
	if (is_array($FldVal)) $FldVal = implode(",", $FldVal);
	$FldVal2 = ew_StripSlashes($FldVal2);
	if (is_array($FldVal2)) $FldVal2 = implode(",", $FldVal2);
	$FldOpr = strtoupper(trim($FldOpr));
	if ($FldOpr == "BETWEEN") {
		$IsValidValue = ($Fld->FldDataType <> EW_DATATYPE_NUMBER) ||
			($Fld->FldDataType == EW_DATATYPE_NUMBER && is_numeric($FldVal) && is_numeric($FldVal2));
		if ($FldVal <> "" && $FldVal2 <> "" && $IsValidValue) {
			$sWrk = "x_" . $FldParm . "=" . urlencode($FldVal) .
				"&y_" . $FldParm . "=" . urlencode($FldVal2) .
				"&z_" . $FldParm . "=" . urlencode($FldOpr);
		}
	} elseif ($FldOpr == "IS NULL" || $FldOpr == "IS NOT NULL") {
		$sWrk = "x_" . $FldParm . "=" . urlencode($FldVal) .
			"&z_" . $FldParm . "=" . urlencode($FldOpr);
	} else {
		$IsValidValue = ($Fld->FldDataType <> EW_DATATYPE_NUMBER) ||
			($Fld->FldDataType = EW_DATATYPE_NUMBER && is_numeric($FldVal));
		if ($FldVal <> "" && $IsValidValue && ew_IsValidOpr($FldOpr, $Fld->FldDataType)) {
			$sWrk = "x_" . $FldParm . "=" . urlencode($FldVal) .
				"&z_" . $FldParm . "=" . urlencode($FldOpr);
		}
		$IsValidValue = ($Fld->FldDataType <> EW_DATATYPE_NUMBER) ||
			($Fld->FldDataType = EW_DATATYPE_NUMBER && is_numeric($FldVal2));
		if ($FldVal2 <> "" && $IsValidValue && ew_IsValidOpr($FldOpr2, $Fld->FldDataType)) {
			if ($sWrk <> "") $sWrk .= "&v_" . $FldParm . "=" . urlencode($FldCond) . "&";
			$sWrk .= "&y_" . $FldParm . "=" . urlencode($FldVal2) .
				"&w_" . $FldParm . "=" . urlencode($FldOpr2);
		}
	}
	if ($sWrk <> "") {
		if ($Url <> "") $Url .= "&";
		$Url .= $sWrk;
	}
}
?>
<?php

// Render row values based on field settings
function RenderRow() {
	global $conn, $Security, $HoaDonPhim;

	// Call Row Rendering event
	$HoaDonPhim->Row_Rendering();

	// Common render codes for all row types
	if ($HoaDonPhim->RowType == EW_ROWTYPE_VIEW) { // View row
	} elseif ($HoaDonPhim->RowType == EW_ROWTYPE_ADD) { // Add row
	} elseif ($HoaDonPhim->RowType == EW_ROWTYPE_EDIT) { // Edit row
	} elseif ($HoaDonPhim->RowType == EW_ROWTYPE_SEARCH) { // Search row

		// bill
		$HoaDonPhim->bill->EditCustomAttributes = "";
		$sSqlWrk = "SELECT `bill`, `bill` FROM `orders_movie`";
		$rswrk = $conn->Execute($sSqlWrk);
		$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
		if ($rswrk) $rswrk->Close();
		array_unshift($arwrk, array("", "Please Select"));
		$HoaDonPhim->bill->EditValue = $arwrk;

		// fullname
		$HoaDonPhim->fullname->EditCustomAttributes = "";
		$HoaDonPhim->fullname->EditValue = ew_HtmlEncode($HoaDonPhim->fullname->AdvancedSearch->SearchValue);

		// email
		$HoaDonPhim->email->EditCustomAttributes = "";
		$HoaDonPhim->email->EditValue = ew_HtmlEncode($HoaDonPhim->email->AdvancedSearch->SearchValue);

		// address
		$HoaDonPhim->address->EditCustomAttributes = "";
		$HoaDonPhim->address->EditValue = ew_HtmlEncode($HoaDonPhim->address->AdvancedSearch->SearchValue);

		// tel
		$HoaDonPhim->tel->EditCustomAttributes = "";
		$HoaDonPhim->tel->EditValue = ew_HtmlEncode($HoaDonPhim->tel->AdvancedSearch->SearchValue);

		// note
		$HoaDonPhim->note->EditCustomAttributes = "";
		$HoaDonPhim->note->EditValue = ew_HtmlEncode($HoaDonPhim->note->AdvancedSearch->SearchValue);

		// dateadd
		$HoaDonPhim->dateadd->EditCustomAttributes = "";
		$HoaDonPhim->dateadd->EditValue = ew_HtmlEncode(ew_FormatDateTime($HoaDonPhim->dateadd->AdvancedSearch->SearchValue, 7));

		// quantity
		$HoaDonPhim->quantity->EditCustomAttributes = "";
		$HoaDonPhim->quantity->EditValue = ew_HtmlEncode($HoaDonPhim->quantity->AdvancedSearch->SearchValue);
	}

	// Call Row Rendered event
	$HoaDonPhim->Row_Rendered();
}
?>
<?php

// Load advanced search
function LoadAdvancedSearch() {
	global $HoaDonPhim;
	$HoaDonPhim->bill->AdvancedSearch->SearchValue = $HoaDonPhim->getAdvancedSearch("x_bill");
	$HoaDonPhim->fullname->AdvancedSearch->SearchValue = $HoaDonPhim->getAdvancedSearch("x_fullname");
	$HoaDonPhim->email->AdvancedSearch->SearchValue = $HoaDonPhim->getAdvancedSearch("x_email");
	$HoaDonPhim->address->AdvancedSearch->SearchValue = $HoaDonPhim->getAdvancedSearch("x_address");
	$HoaDonPhim->tel->AdvancedSearch->SearchValue = $HoaDonPhim->getAdvancedSearch("x_tel");
	$HoaDonPhim->note->AdvancedSearch->SearchValue = $HoaDonPhim->getAdvancedSearch("x_note");
	$HoaDonPhim->dateadd->AdvancedSearch->SearchValue = $HoaDonPhim->getAdvancedSearch("x_dateadd");
	$HoaDonPhim->quantity->AdvancedSearch->SearchValue = $HoaDonPhim->getAdvancedSearch("x_quantity");
}
?>
<?php

// Page Load event
function Page_Load() {

	//echo "Page Load";
}

// Page Unload event
function Page_Unload() {

	//echo "Page Unload";
}
?>
